package com.share.demo.event;

import com.share.demo.dao.UserRepository;
import com.share.demo.domain.User;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;

import java.util.Date;

/**
 * author:caifan
 * date:2019/11/29
 */
public class MsgEvent extends ApplicationEvent {

    UserRepository userRepository;

    @Getter
    @Setter
    User user;
    /**
     * Create a new ApplicationEvent.
     *
     * @param source the object on which the event initially occurred (never {@code null})
     */
    public MsgEvent(Object source, UserRepository userRepository) {
        super(source);
        this.userRepository = userRepository;
    }

    public void getUserMsg() {
        user = new User();
        user.setAge(22);
        user.setEmail("zhangsan@163.com");
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        userRepository.save(user);
        System.out.println(user.toString());
    }

}
